<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'studentList.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<link href="css/mytablecss.css" rel="stylesheet" type="text/css" />
</head>

<body>
	<h3 style="padding:15px;">学生列表</h3>
	<a class="mybtn f-r mgr" id="upload_user">批量导入学生</a>
	<div class="pd-20">
		<!-- <div class="text-c">
	  <form action="findbymob">
		<input type="text" class="input-text" style="width:180px" placeholder="输入电话" id="mobile" name="mobile">
		<input type="submit" class="btn btn-success radius" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜用户</button>
	  </form>
	</div>  -->

		<div class="mt-20">
			<table
				class="table table-border table-bordered table-hover table-bg table-sort">
				<thead>
					<tr class="text-c">
						<!-- <th width="80">序号</th> -->
						<th width="100">姓名</th>
						<th width="200">身份证</th>
						<th width="200">教育层次</th>
						<th width="150">专业</th>
						<th width="100">联系电话</th>
						<th width="200">注册时间</th>
						<th width="200">最近登陆时间</th>
						<th width="100">最近登陆ip</th>
						<th width="100">操作</th>
					</tr>
				</thead>
				<tbody>
					<c:forEach items="${requestScope.userList}" var="user">
						<tr>
							<td value="${user.id}"><c:out value="${user.name}"></c:out></td>
							<td value="${user.password}"><c:out value="${user.identity}"></c:out></td>
							<td value="${user.email}"><c:out
									value="${user.education_level}"></c:out></td>
							<td value="${user.sex}"><c:out value="${user.major}"></c:out></td>
							<td><c:out value="${user.phone}"></c:out></td>
							<td><c:out value="${user.create_time}"></c:out></td>
							<td><c:out value="${user.login_time}"></c:out></td>
							<td><c:out value="${user.login_ip}"></c:out></td>
							<%-- <td style="display:none"><c:out value="${manager.id}"></c:out></td> --%>
							<td class="td-manage"><a title="编辑" class="ml-5 edit"
								style="text-decoration:none" onclick="edit(this)"> <i
									class="Hui-iconfont">&#xe6df;</i></a> <a
								style="text-decoration:none" class="ml-5"
								onClick="alterPassword(this)" title="修改密码"> <i
									class="Hui-iconfont">&#xe63f;</i></a> <!-- <a title="删除"
								href="javascript:;" onclick="remove(this)" class="ml-5"
								style="text-decoration:none"> <i class="Hui-iconfont">&#xe6e2;</i></a> --></td>
						</tr>
					</c:forEach>
				</tbody>
			</table>
		</div>
	</div>

	<div id="bcg_upload" class="editor_background">
		<form class="editor_upload form form-horizontal" method="post"
			action="/ExamSystem/UploadServlet" enctype="multipart/form-data"
			onsubmit="return check();">
			<legend> 导入excel窗口 </legend>
			<div>
				<span class="btn-upload form-group"> <input id="i_path"
					class="input-text upload-url" type="text" name="uploadfile-2"
					style="width:200px" id="uploadfile-2" readonly> <a
					href="javascript:void();" class="btn btn-primary upload-btn"
					style="font-size: 17px;padding:4px"> 浏览文件</a> <input type="file"
					multiple name="file-2" class="input-file"
					style="width: 285px;height: 40px;">
				</span> <input id="btn_ensure3" class="btn btn-primary f-l btn_ensure"
					style="width: 75px;margin-left: 100px;" value="确认" readonly
					type="submit"> <input id="btn_exit3"
					class="btn btn-primary f-l btn_exit" value="取消" readonly>
			</div>
		</form>
	</div>

	<div id="bcg_editor" class="editor_background">
		<form id="user_editor_form" class="editor_main form form-horizontal">
			<legend>学生信息窗口 </legend>
			<div style="margin-left: 21%;">
				<div class="row">
					<label class="form-label col-xs-4 col-sm-3">姓名:</label>
					<div class="formControls col-xs-8 col-sm-9 input_manager">
						<input id="i_name" name="i_name" class="input-text" type="text">
					</div>
				</div>
				<br />
				<div class="row" style="margin-top: 25px;">
					<label class="form-label col-xs-4 col-sm-3">身份证号:</label>
					<div class="formControls col-xs-8 col-sm-9 input_manager">
						<input id="i_identity" name="i_identity" class="input-text"
							type="text">
					</div>
				</div>
				<br />
				<div class="row" style="margin-top: 25px;">
					<label class="form-label col-xs-4 col-sm-3">性别:</label>
					<div class="formControls col-xs-8 col-sm-9 input_manager">
						<span class="select-box "><select id="sel_sex"
							class="select" size="1" name="sel_sex">
								<option value="男">男</option>
								<option value="女">女</option>
						</select> </span>
					</div>
				</div>
				<br />
				<div class="row" style="margin-top: 25px;">
					<label class="form-label col-xs-4 col-sm-3">教育层次:</label>
					<div class="formControls col-xs-8 col-sm-9 input_manager">
						<input id="i_education_level" name="i_education_level"
							class="input-text" type="text">
					</div>
				</div>
				<br />
				<div class="row" style="margin-top: 25px;">
					<label class="form-label col-xs-4 col-sm-3">专业:</label>
					<div class="formControls col-xs-8 col-sm-9 input_manager">
						<span class="select-box "><select id="sel_major"
							class="select" size="1" name="sel_major" disabled>
						</select> </span>
					</div>
				</div>
				<br />
				<div class="row" style="margin-top: 25px;">
					<label class="form-label col-xs-4 col-sm-3">联系电话 :</label>
					<div class="formControls col-xs-8 col-sm-9 input_manager">
						<input id="i_phone" name="i_phone" class="input-text" type="text">
					</div>
				</div>
				<br />
				<div class="row" style="margin-top: 25px;">
					<label class="form-label col-xs-4 col-sm-3">E_mail:</label>
					<div class="formControls col-xs-8 col-sm-9 input_manager">
						<input id="i_email" name="i_email" class="input-text" type="text">
					</div>
				</div>
				<br />
				<div class="row" style="margin-top: 25px;">
					<label class="form-label col-xs-4 col-sm-3">注册时间:</label>
					<div
						class="formControls skin-minimal col-xs-8 col-sm-9 input_manager">
						<input id="i_register_time" name="i_register_time"
							class="input-text" type="text" disabled>
					</div>
				</div>
				<br />
				<div class="row" style="margin-top: 25px;">
					<label class="form-label col-xs-4 col-sm-3">最近登陆时间:</label>
					<div
						class="formControls skin-minimal col-xs-8 col-sm-9 input_manager">
						<input id="i_login_time" name="i_login_time" class="input-text"
							type="text" disabled>
					</div>
				</div>
				<br />
				<div class="row" style="margin-top: 25px;">
					<label class="form-label col-xs-4 col-sm-3">最近登陆ip:</label>
					<div
						class="formControls skin-minimal col-xs-8 col-sm-9 input_manager">
						<input id="i_login_ip" name="i_login_ip" class="input-text"
							type="text" disabled>
					</div>
				</div>
				<br />

				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
					<input id="btn_ensure" class="btn btn-primary f-l btn_ensure"
						style="width: 75px;" value="确认" readonly> <input
						id="btn_exit" class="btn btn-primary f-l btn_exit" value="取消"
						readonly>
				</div>
				<input id="user_id" name="user_id" class="input-text" type="text"
					style="display:none;">
			</div>
		</form>
	</div>

	<div id="bcg_alter_password" class="editor_background">
		<form id="user_alterpwd_form" class="editor_main form form-horizontal">
			<legend>修改密码窗口 </legend>
			<div style="margin-left: 21%;">
				<div class="row" style="margin-top: 25px;">
					<label class="form-label col-xs-4 col-sm-3">新的密码:</label>
					<div class="formControls col-xs-8 col-sm-9 input_manager">
						<input id="i_new_password" name="i_new_password"
							class="input-text" type="password">
					</div>
				</div>
				<br />
				<div class="row" style="margin-top: 25px;">
					<label class="form-label col-xs-4 col-sm-3">确认密码:</label>
					<div class="formControls col-xs-8 col-sm-9 input_manager">
						<input id="i_ensure_password" name="i_ensure_password"
							class="input-text" type="password">
					</div>
				</div>
				<br />
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
					<input id="btn_ensure2" class="btn btn-primary f-l btn_ensure"
						style="width: 75px;" value="确认" readonly> <input
						id="btn_exit2" class="btn btn-primary f-l btn_exit" value="取消"
						readonly>
				</div>
				<input id="user_id2" name="user_id2" class="input-text" type="text"
					style="display:none;">
			</div>
		</form>
	</div>

</body>
<script type="text/javascript">
	$(function() {
		$('.table-sort').dataTable({
			"aaSorting" : [ [ 0, "asc" ] ],//默认第几个排序
			"bStateSave" : true,//状态保存 
			"bRetrieve" : true,
			"aoColumnDefs" : [
			//{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
			//{"orderable":false,"aTargets":[7]}// 制定列不参与排序
			]
		});
	});

	//编辑窗口取消按钮
	$(function() {
		$('#btn_exit').on('click', function() {
			$('#bcg_editor').hide();
		});
		$('#btn_exit2').on('click', function() {
			setEmpty();
			$('#bcg_alter_password').hide();
		});
		$('#btn_exit3').on('click', function() {
			setEmpty();
			$('#bcg_upload').hide();
		});
	});
	//编辑窗口确认按钮
	$(function() {
		//修改用户信息窗口
		$('#btn_ensure').on('click', function() {
			//验证表单信息
			if (!$("#user_editor_form").valid()) {
				return false;
			}
			if (!confirm("确认修改?")) {
				return false;
			}
			//提交修改信息逻辑
			var studentInfo = {
				user_id : $("#user_id").val(),
				name : $("#i_name").val(),
				identity : $("#i_identity").val(),
				phone : $("#i_phone").val(),
				sex : $("#sel_sex").val(),
				createTime : $("#i_register_time").val(),
				education_level : $("#i_education_level").val(),
				email : $("#i_email").val(),
				education_major : $("#sel_major").val(),
				login_time : $("#i_login_time").val(),
				login_ip : $("#i_login_ip").val(),
			};

			console.log("studentList 287");
			console.log(studentInfo);

			$.ajax({
				"data" : studentInfo,
				"url" : "./AlterManagerInfoServlet?method=studentList",
				"type" : "POST",
				"success" : function(result) {
					var resultJson = JSON.parse(result);
					if (resultJson.code == "200") {
						alert("修改成功");

						//刷新页面
						$.post("./StudentListServlet", function(data) {
							$('#content').html(data);

						});
					} else {
						alert("修改失败");
					}
				}
			});
		});

		//修改密码窗口
		$('#btn_ensure2').on('click', function() {
			//验证表单信息
			if (!$("#user_alterpwd_form").valid()) {
				return false;
			}
			if (!confirm("确认修改?")) {
				return false;
			}
			//提交修改信息逻辑
			var studentInfo = {
				user_id : $("#user_id2").val(),
				password : $("#i_new_password").val()
			};
			console.log(studentInfo);
			/* $.ajax({
			"data" : studentInfo,
			"url" : "",
			"type" : "POST",
			"success" : function(result) {
				var resultJson = JSON.parse(result);
				if (resultJson.code == "200") {
					
					alert("修改成功");
					//刷新页面
					$.post("./StudentListServlet", function(data) {
						$('#content').html(data);
						
					});
				} else {
					alert("修改失败");
				}
			}
			}); */
		});

		//批量导入学生确定按钮
		$("#btn_ensure3").on("click", function() {
			//批量导入学生excel 逻辑操作
		});
	});

	//删除按钮
	function remove(widget) {
		//删除数据逻辑
	}

	//修改密码
	function alterPassword(widget) {
		var i = 0;
		$(widget).parent("td").siblings("td").each(function() {
			switch (i) {
			case 0:
				//姓名
				$('#user_id2').val($(this).attr("value"));
				break;
			}
			i++;
		});
		$('#bcg_alter_password').show();
	}

	//批量导入学生按钮
	$(function() {
		$('#upload_user').on('click', function() {
			$('#bcg_upload').show();
		});
	});
	
	$(function(){
		function getMajorSelect() {
			$.ajax({
				"data" : "",
				"url" : "./AlterManagerInfoServlet?method=getMajorSelect",
				"type" : "POST",
				"success" : function(result) {
					var resultJson = JSON.parse(result);
					if (resultJson.code == "200") {
						$("#sel_major").children("option").remove();
						$.each(resultJson.major, function(index, value) {
							/* console.log(value); */
							var text = "<option value="+value+">" + value
									+ "</option>";
							$("#sel_major").append(text);
						});
						/* console.log(resultJson.major); */
					} else {
						console.log("系统出错");
					}
				}
			});
		}
	});
	
	//编辑按钮
	function edit(widget) {
		var i = 0;
		$(widget).parent("td").siblings("td").each(function() {
			switch (i) {
			case 0:
				//姓名
				$('#user_id').val($(this).attr("value"));
				$('#i_name').val($(this).text());
				break;
			case 1:
				//身份证
				$('#i_identity').val($(this).text());
				break;
			case 2:
				//教育层次
				$('#i_email').val($(this).attr("value"));
				$('#i_education_level').val($(this).text());
				break;
			case 3:
				//专业
				$("#sel_sex").val($(this).attr("value"));
				$("#sel_major").val($(this).text());
				break;
			case 4:
				//电话
				$('#i_phone').val($(this).text());
				break;
			case 5:
				//注册时间
				$('#i_register_time').val($(this).text());
				break;
			case 6:
				//最近登陆时间
				$('#i_login_time').val($(this).text());
				break;
			case 7:
				//最近登陆ip
				$('#i_login_ip').val($(this).text());
				break;
			}
			i++;
		});

		$('#bcg_editor').show();
	}

	//清空按钮
	function setEmpty() {
		$("#i_ensure_password").val("");
		$("#i_new_password").val("");
		$("#i_path").val("");
	}
	//修改密码窗口
	$("#user_alterpwd_form").validate({
		rules : {
			i_new_password : {
				required : true,
				minlength : 6,
				maxlength : 20
			},
			i_ensure_password : {
				required : true,
				minlength : 6,
				maxlength : 20,
				equalTo : "#i_new_password"
			}
		},
		onkeyup : false,
		focusCleanup : true,
		success : "valid"
	});
	//修改信息窗口
	$("#user_editor_form").validate({
		rules : {
			i_name : {
				required : true,
				maxlength : 20
			},
			i_identity : {
				required : true,
				minlength : 18,
				maxlength : 18
			},
			sel_sex : {
				required : true,
			},
			i_education_level : {
				required : true,
			},
			sel_major : {
				required : true,
			},
			i_phone : {
				required : true,
				minlength : 11,
			},
			i_email : {
				required : true,
				email : true,
			}
		},
		onkeyup : false,
		focusCleanup : true,
		success : "valid"
	});
</script>
</html>